<!-- <template>
    <BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="title" :width="800" @ok="handleSubmit">
        <BasicForm @register="registerForm" />
    </BasicModal>
</template>

<script lang="ts" setup>
import { ref, computed, unref } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
// import { formSchema } from '../NurseNurses.data';
import { saveOrUpdate } from '../NurseNurses.api';

const formSchema: FormSchema[] = [
    {
        label: '护工姓名',
        field: 'name',
        component: 'Input',
        dynamicRules: ({ model, schema }) => {
            return [
                { required: true, message: '请输入护工姓名!' },
            ];
        },
    },
    {
        label: '头像',
        field: 'avatar',
        component: 'JImageUpload',
        componentProps: {
            fileMax: 1
        },
    },

    {
        label: '身份证号',
        field: 'idcard',
        component: 'Input',
    },
    {
        label: '手机号码',
        field: 'phone',
        component: 'Input',
        dynamicRules: ({ model, schema }) => {
            return [
                { required: true, message: '请输入手机号码!' },
            ];
        },
    },
    {
        label: '是否有效',
        field: 'status',
        component: 'JDictSelectTag',
        defaultValue: '1',
        componentProps: {
            dictCode: "valid_status"
        },
        dynamicRules: ({ model, schema }) => {
            return [
                { required: true, message: '请输入是否有效!' },
            ];
        },
    },
    {
        label: '性别',
        field: 'sex',
        component: 'JDictSelectTag',
        componentProps: {
            dictCode: "nurse_sex"
        },
    },
    {
        label: '是否显示到微信',
        field: 'isShow',
        component: 'JDictSelectTag',
        componentProps: {
            dictCode: "nurse_is_show"
        },
    },
    {
        label: '是否专家',
        field: 'isExpert',
        component: 'JDictSelectTag',
        componentProps: {
            dictCode: "nurse_is_expert"
        },
    },
    {
        label: '费用',
        field: 'fee',
        component: 'InputNumber',
        defaultValue: 0,
    },
    {
        label: '隶属机构',
        span: 10,
        field: 'hospital',
        component: 'JSelectMultiple',
        componentProps: {
            options: [],
        },
    },

    {
        label: '服务年限',
        field: 'life',
        component: 'InputNumber',
    },
    {
        label: '服务人数',
        field: 'serverNumber',
        component: 'InputNumber',
    },
    {
        label: '地区',
        field: 'area',
        component: 'Input',
    },
    {
        label: '地区名称',
        field: 'areaName',
        component: 'Input',
    },
    {
        label: '评分',
        field: 'rate',
        component: 'InputNumber',
    },
    {
        label: '简介',
        field: 'profile',
        component: 'InputTextArea',//TODO 注意string转换问题
    },
    {
        label: '微信openid',
        field: 'openid',
        component: 'Input',
    },
    {
        label: '微信unionid',
        field: 'unionid',
        component: 'Input',
    },

    // {
    //   label: '佣金比例',
    //   field: 'ratio',
    //   component: 'InputNumber',
    //   dynamicRules: ({ model, schema }) => {
    //     return [
    //       { required: true, message: '请输入佣金比例!' },
    //     ];
    //   },
    // },
    // TODO 主键隐藏字段，目前写死为ID
    {
        label: '',
        field: 'id',
        component: 'Input',
        show: false
    },
];

// Emits声明
const emit = defineEmits(['register', 'success']);
const isUpdate = ref(true);
//表单配置
const [registerForm, { setProps, resetFields, setFieldsValue, validate }] = useForm({
    //labelWidth: 150,
    schemas: formSchema,
    showActionButtonGroup: false,
    baseColProps: { span: 24 }
});
//表单赋值
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
    //重置表单
    await resetFields();
    setModalProps({ defaultFullscreen: true, confirmLoading: false, showCancelBtn: !!data?.showFooter, showOkBtn: !!data?.showFooter });
    isUpdate.value = !!data?.isUpdate;
    if (unref(isUpdate)) {
        //表单赋值
        await setFieldsValue({
            ...data.record,
        });
    }
    // 隐藏底部时禁用整个表单
    setProps({ disabled: !data?.showFooter })
});
//设置标题
const title = computed(() => (!unref(isUpdate) ? '新增' : '编辑'));
//表单提交事件
async function handleSubmit(v) {
    try {
        let values = await validate();
        setModalProps({ confirmLoading: true });
        //提交表单
        await saveOrUpdate(values, isUpdate.value);
        //关闭弹窗
        closeModal();
        //刷新列表
        emit('success');
    } finally {
        setModalProps({ confirmLoading: false });
    }
}
</script>

<style lang="less" scoped>
/** 时间和数字输入框样式 */
:deep(.ant-input-number) {
    width: 100%
}

:deep(.ant-calendar-picker) {
    width: 100%
}
</style> -->



<template>
    <a-modal :title="title" :width="width" :visible="visible" @ok="handleOk"
        :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }" @cancel="handleCancel" cancelText="关闭">
        <NurseNursesForm ref="registerForm" @ok="submitCallback" :formDisabled="disableSubmit" :formBpm="false">
        </NurseNursesForm>
    </a-modal>
</template>

<script lang="ts" setup>
import { ref, nextTick, defineExpose } from 'vue';
import NurseNursesForm from './NurseNursesForm.vue'

const title = ref<string>('');
const width = ref<number>(800);
const visible = ref<boolean>(false);
const disableSubmit = ref<boolean>(false);
const registerForm = ref();
const emit = defineEmits(['register', 'success']);

/**
 * 新增
 */
function add() {
    title.value = '新增';
    visible.value = true;
    nextTick(() => {
        registerForm.value.add();
    });
}

/**
 * 编辑
 * @param record
 */
function edit(record) {
    title.value = disableSubmit.value ? '详情' : '编辑';
    visible.value = true;
    nextTick(() => {
        registerForm.value.edit(record);
    });
}

/**
 * 确定按钮点击事件
 */
function handleOk() {
    registerForm.value.submitForm();
}

/**
 * form保存回调事件
 */
function submitCallback() {
    handleCancel();
    emit('success');
}

/**
 * 取消按钮回调事件
 */
function handleCancel() {
    visible.value = false;
}

defineExpose({
    add,
    edit,
    disableSubmit,
});
</script>

<style>
/**隐藏样式-modal确定按钮 */
.jee-hidden {
    display: none !important;
}
</style>
